﻿using System;
using System.Reflection;
using System.Web.Mvc;

namespace CodeContrib.Web.Mvc
{
	[AttributeUsage(AttributeTargets.Method, Inherited = true)]
	public class MultiButtonAttribute : ActionMethodSelectorAttribute
	{
		private readonly string _buttonName;

		public MultiButtonAttribute(string buttonName)
		{
			Guard.NotNullOrEmpty(buttonName, "buttonName");

			_buttonName = buttonName;
		}

		public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
		{
			return (controllerContext.RequestContext.HttpContext.Request[_buttonName] != null);
		}
	}
}